package lanqiao13;

import java.util.Scanner;

public class E {
	private static int n;// 结点数
	private static int m;// 路数
	private static int s;// 起点
	private static int t;// 终点
	private static int[][] roads;// 存储每条路
	private static int time = -1;// 时间
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        m = scan.nextInt();
        s = scan.nextInt();
        t = scan.nextInt();
        roads = new int[m][6];
        for (int i = 0; i < m; i++) {
			roads[i][5] = 0;
		}
        for (int i = 0; i < m; i++) {
			for (int j = 0; j < 5; j++) {
				roads[i][j] = scan.nextInt();
			}
		}
        
        dfs(s, 0);
        System.out.println(time);
        scan.close();
        
        
	}
	
	private static void dfs(int newS, int count) {
		if (newS == t) {
			if (time == -1) {
				time = count;
			} else {
				time = Math.min(time, count);
			}
			return;
		}
		
		for (int i = 0; i < roads.length; i++) {
			int loop = roads[i][2] + roads[i][3] + roads[i][4] * 2;
			int green = roads[i][2];
			int red = roads[i][3];
			int yellow = roads[i][4];
			if (roads[i][5] == 0 && (roads[i][0] == newS || roads[i][1] == newS)) {
				roads[i][5] = 1;
				if (roads[i][0] == newS) {
					if (count % loop < green) {
						count += yellow;
						dfs(roads[i][1], count);
						count -= yellow;
					} else {
						count += (count / loop + 1) * loop + yellow;
						dfs(roads[i][1], count);
						count -= (count / loop + 1) * loop + yellow;
					}
				} else {
					if ((count - green - yellow) % loop < red) {
						count += yellow;
						dfs(roads[i][0], count);
						count -= yellow;
					} else {
						count += ((count - green - yellow) % loop + 1) * loop + green + yellow * 2;
						dfs(roads[i][0], count);
						count -= ((count - green - yellow) % loop + 1) * loop + green + yellow * 2;
					}
				}
				roads[i][5] = 0;
			}
		}
	}
}
